package com.gvtv.main.util;

import java.io.File;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

public class AppTools {

	public static Pattern pa = Pattern.compile("\\$\\{(.+?)\\}", Pattern.CASE_INSENSITIVE);
	private static DateTimeFormatter format = DateTimeFormat.forPattern(Constant.NOW_DATETIME_STR_FORMAT);

	/**
	 * 获取系统的根目录
	 * @return
	 */
	public static String getBaseDir() {
		return new File(Thread.currentThread().getContextClassLoader().getResource("").getPath()).getParent();
	}

	/**
	 * 根据时间获取唯一ID
	 * @return
	 */
	public synchronized static String getUniqueID() {
		return new DateTime().toString(format);
	}

	/**
	 * \r\r  ---> \n
	 * @param str
	 * @return
	 */
	public static String replaceBlank(String str) {
		/*String dest = "";
		if (str != null) {
			Pattern p = Pattern.compile("\r\n");
			Matcher m = p.matcher(str);
			dest = m.replaceAll("\n");
		}*/
		if(StringUtils.isBlank(str)){
			return str;
		}
		return str.replaceAll("\r\n", "\n");
	}

	/*public static void main(String[] args) {
		System.out.println(getBaseDir());
		System.out.println(getUniqueID());
		System.out.println(replaceBlank("select\r * from  \r\n t1\r"));
	}*/

}
